package com.zhangjun;

import com.zhangjun.entity.Student;
import com.zhangjun.mapper.StudentMapper;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


/**
 * @author 张钧
 * @Description
 * @create 2022-10-14 12:59
 */
public class MybatisTest {

	StudentMapper studentMapper;



	@Before
	public void before() {
		ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
		studentMapper = (StudentMapper) context.getBean("studentMapper");
	}

	@Test
	public void insertStudent() {
		System.out.println(studentMapper.insertStudent(new Student().setName("赵六").setScore(30).setSpecial("美术")));
	}

	@Test
	public void updateStudent() {
		System.out.println(studentMapper.updateStudent(new Student().setId(1L).setName("王五").setScore(90)));
	}

	@Test
	public void deleteStudent(){
		System.out.println(studentMapper.deleteStudent(1L));
	}

	@Test
	public void selectStudent(){
		System.out.println(studentMapper.selectStudent(3L));
	}

	@Test
	public void selectAllStudent(){
		System.out.println(studentMapper.selectAllStudent());
	}

	@Test
	public void selectStudentByCondition(){
		System.out.println(studentMapper.selectStudentByCondition(new Student().setName("王五")));
	}
}
